package com.lq.demo.demo.mode.constructormode;


import lombok.Data;

/**
 * 简单的建造者模式  demo  链式调用
 */
public class ContructDemo {
    public static void main(String[] args) {
        User buildUser = new User.UserBuilder()
                .setAddress("四川")
                .setAge(21)
                .setName("lily")
                .setPhone("1234343333")
                .build();
        System.out.println(buildUser);
    }
}

@Data
class User {
    private String name;
    private Integer age;
    private String address;
    private String phone;

    private User(UserBuilder builder) {
        name = builder.name;
        age = builder.age;
        address = builder.address;
        phone = builder.phone;

    }

    static class UserBuilder {

        private String name;
        private Integer age;
        private String address;
        private String phone;

        public UserBuilder() {
        }

        public UserBuilder setName(String name) {
            this.name = name;
            return this;
        }

        public UserBuilder setAge(Integer age) {
            this.age = age;
            return this;
        }

        public UserBuilder setAddress(String address) {
            this.address = address;
            return this;
        }

        public UserBuilder setPhone(String phone) {
            this.phone = phone;
            return this;
        }

        public User build() {
            return new User(this);
        }
    }

}
